<template>

    <el-card class="box-card">
      <div>
      <el-form :model="resourceForm">

        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="数据资产名称">
              <el-input v-model="resourceForm.resourceName"  placeholder="数据资产名称"></el-input>
            </el-form-item>
          </el-col>
<!--          <el-col :span="4">-->
<!--            <el-form-item label="数据资产包描述">-->
<!--              <el-input v-model="resourceForm.miao" placeholder="数据资产包描述"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="4">-->
<!--            <el-form-item label="数据资产标签">-->
<!--              <el-input v-model="resourceForm.status" placeholder="数据资产标签"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
        <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="数据资产包描述">
            <el-input v-model="resourceForm.miao" placeholder="数据资产包描述"></el-input>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="11">
            <el-form-item label="需要上传文件">
              <el-upload
                class="avatar-uploader"
                action="/api/resource/upload"
                :headers="auth"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload">
                <img v-if="resourceForm.wenjian!= null" :src="'/api/resource/download/'+resourceForm.wenjian" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="userFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveResource()">确 定</el-button>
      </div>



  </div>
  </el-card>
</template>

<script>
  export default {
    name: 'UserList',
    data(){
      return{
        multipleSelection:[],
        names:[],
        user:{},

        resourceForm:{
          wenjian:'',
          status:0
        },
        userForm:{},
        auth:{token:null},

        resourcelist:[],
        searchForm:{},
        page: {
          pagenum: 0,
          pagesize: 2
        },
        total: 0,
      }
    },
    methods: {


      crearUserForm: function () {
        this.userForm = {};
      },
      saveResource: function () {
        this.resourceForm.uid = this.user.id;
        this.$http.post("/resource/save", this.resourceForm).then((res) => {
          if (res.data.success) {
            this.resourceForm = {};
            this.$message.success(res.data.message);
            this.$router.push("/resourcelist")
          } else {
            this.$message.error(res.data.message);
          }
        })
      },
      handleAvatarSuccess (res, file) {
        this.resourceForm.wenjian = res.result.path;
      },
      beforeAvatarUpload (file) {
        const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },

    },
    mounted () {
      this.user = JSON.parse(sessionStorage.getItem("user"))
      this.auth.token = sessionStorage.getItem("token")
    }
  }
</script>

<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 1580px;
  }
</style>
